<!DOCTYPE html>
<html lang="zh_Ch">
    <head>
  <!-- 元数据 -->
  <meta charset="utf-8">
  
  
  <title>Js-sku商品规则 | Blog</title>
  
  <meta name="author" content="Sun Liusen" />
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="format-detection" content="telphone=no, email=no" />
  
    <meta name="keywords" content="前端" />
  
  <meta name="description" content="Js代码片段123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172const options &#x3D; [&amp;#123;		title: &quot;颜色&quot;,		values: [&amp;">
<meta property="og:type" content="article">
<meta property="og:title" content="Js-sku商品规则">
<meta property="og:url" content="https://slsandxr.top/2023/08/31/JS/Js-sku%E5%95%86%E5%93%81%E8%A7%84%E5%88%99/index.html">
<meta property="og:site_name" content="Blog">
<meta property="og:description" content="Js代码片段123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172const options &#x3D; [&amp;#123;		title: &quot;颜色&quot;,		values: [&amp;">
<meta property="og:locale" content="zh_CH">
<meta property="article:published_time" content="2023-08-31T07:08:19.000Z">
<meta property="article:modified_time" content="2024-12-16T11:07:04.232Z">
<meta property="article:author" content="Sun Liusen">
<meta property="article:tag" content="前端">
<meta name="twitter:card" content="summary">
  
  <!-- 站点验证相关 -->
  
    
    
    
  
  <!-- 样式表文件 -->
  <link rel="stylesheet" id="kratos-css" href="/css/kratosr.min.css" media="all"></script>
  
    <link rel="stylesheet" id="darkmode-css" href="/css/kr-color-dark.min.css" media="(prefers-color-scheme: dark)"></script>
    <script src="/js/kr-dark.min.js"></script>
  
  
    <link rel="stylesheet" id="highlight-css" href="/css/highlight/night-eighties.min.css" media="all"></script>
  
  <link rel="stylesheet" id="fontawe-css" href="/vendors/font-awesome@4.7.0/css/font-awesome.min.css" media="all"></script>
  <link rel="stylesheet" id="nprogress-css" href="/vendors/nprogress@0.2.0/nprogress.css" media="all"></script>
  
  
    <link rel="stylesheet" href="/vendors/aplayer@1.10.1/dist/APlayer.min.css"></script>
  
  
    <link rel="stylesheet" href="/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css"></script>
  
  <!-- 不得不预先加载的一些JS文件 -->
  <script src="/vendors/jquery@3.6.0/dist/jquery.min.js"></script>
  
    <script src="/vendors/qrcode_js@1.0.0/qrcode.min.js"></script>
  
  
  <style>
    
    
  </style>
  
<meta name="generator" content="Hexo 6.3.0"></head>


    <body class="custom-background">
        <div id="kratos-wrapper">
    <div id="kratos-page">
        <div id="kratos-header">
            <header id="kratos-desktop-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="nav-header">
                        <nav id="kratos-menu-wrap">
                            <ul id="kratos-primary-menu" class="sf-menu">
                                
                                    
                                    
                                
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
            <header id="kratos-mobile-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="color-logo"><a href="/">Blog</a></div>
                    <div class="nav-toggle">
                        <a class="kratos-nav-toggle js-kratos-nav-toggle">
                            <i></i>
                        </a>
                    </div>
                </div>
            </header>
        </div>
        <div class="kratos-start kratos-hero-2">
            <!-- <div class="kratos-overlay"></div> -->
            <div class="kratos-cover kratos-cover-2 text-center">
                <div class="desc desc2 animate-box">
                    <a href="/">
                        <h2>Blog</h2> <br />
                        <span></span>
                    </a>
                </div>
            </div>
        </div>

        <div id="kratos-blog-post">
            <div class="container">
                <div id="main" class="row">
                    

        

            <section class="col-md-8">

        

            <article itemscope itemtype="https://schema.org/Article">
    
    <link itemprop="mainEntityOfPage" href="https://slsandxr.top/2023/08/31/JS/Js-sku%E5%95%86%E5%93%81%E8%A7%84%E5%88%99/">
    <div class="kratos-hentry kratos-post-inner clearfix">
        <header class="kratos-entry-header">
            
                <h1 class="kratos-entry-title text-center" itemprop="name headline">Js-sku商品规则</h1>
            
            
            <ul class="kratos-post-meta text-center">
                <li><time datetime="2023-08-31T07:08:19.000Z" itemprop="datePublished"><i class="fa fa-calendar"></i> 2023-08-31</time></li>
                <li itemprop="author" itemscope itemtype="https://schema.org/Person">
                    <i class="fa fa-user"></i> 作者 <span itemprop="name">Sun Liusen</span>
                </li>
                
                    <li>
                        <i class="fa fa-edit"></i> 
                        
                        
                            ~23.60K
                        
                        字
                    </li>
                
                
            </ul>
        </header>
        <div class="kratos-post-content">
            
            <div id="expire-alert" class="alert alert-warning hidden" role="alert">
                <div class="icon"><i class="fa fa-warning"></i></div>
                <div class="text"><p>本文最后编辑于 <time datetime="1734347224232"></time> 前，其中的内容可能需要更新。</p></div>
            </div>
            
            
            
            <hr />
            <div itemprop="articleBody"><h2 id="Js代码片段"><a href="#Js代码片段" class="headerlink" title="Js代码片段"></a>Js代码片段</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line">const options = [&#123;</span><br><span class="line">		title: &quot;颜色&quot;,</span><br><span class="line">		values: [&quot;红色&quot;, &quot;蓝色&quot;, &quot;绿色&quot;]</span><br><span class="line">	&#125;,</span><br><span class="line">	&#123;</span><br><span class="line">		title: &quot;尺寸&quot;,</span><br><span class="line">		values: [&quot;S&quot;, &quot;M&quot;, &quot;L&quot;]</span><br><span class="line">	&#125;,</span><br><span class="line">	&#123;</span><br><span class="line">		title: &quot;材质&quot;,</span><br><span class="line">		values: [&quot;棉&quot;, &quot;丝绸&quot;, &quot;麻&quot;]</span><br><span class="line">	&#125;</span><br><span class="line">];</span><br><span class="line"></span><br><span class="line">function generateSKUs(options, initialStock) &#123;</span><br><span class="line">	const skus = [];</span><br><span class="line">	function backtrack(combination, optionIndex) &#123;</span><br><span class="line">		if (optionIndex === options.length) &#123;</span><br><span class="line">			const sku = &#123;</span><br><span class="line">				combination: combination.slice(),</span><br><span class="line">				stock: initialStock</span><br><span class="line">			&#125;;</span><br><span class="line">			skus.push(sku);</span><br><span class="line">			return;</span><br><span class="line">		&#125;</span><br><span class="line">		const currentOption = options[optionIndex];</span><br><span class="line">		for (let i = 0; i &lt; currentOption.values.length; i++) &#123;</span><br><span class="line">			combination[optionIndex] = currentOption.values[i];</span><br><span class="line">			backtrack(combination, optionIndex + 1);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	backtrack([], 0);</span><br><span class="line">	return skus;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">const skus = generateSKUs(options, 10);</span><br><span class="line">function getStockByCombination(skus, combination) &#123; //获取库存</span><br><span class="line">	for (const sku of skus) &#123;</span><br><span class="line">		if (JSON.stringify(sku.combination) === JSON.stringify(combination)) &#123;</span><br><span class="line">			return sku.stock;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	return 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">function decreaseStock(skus, combination, quantity) &#123; // 减少库存</span><br><span class="line">	for (const sku of skus) &#123;</span><br><span class="line">		if (JSON.stringify(sku.combination) === JSON.stringify(combination)) &#123;</span><br><span class="line">			sku.stock -= quantity;</span><br><span class="line">			return sku.stock &gt;= 0;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	return false;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">console.log(&#x27;原始数据&#x27;, options)</span><br><span class="line">console.log(&#x27;sku化数据:&#x27;, skus);</span><br><span class="line"></span><br><span class="line">const stock1 = getStockByCombination(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;]);</span><br><span class="line">console.log(stock1); // 输出初始库存 10</span><br><span class="line"></span><br><span class="line">// 减少红色、M 尺寸、棉材质的库存数量 3</span><br><span class="line">const success1 = decreaseStock(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;], 3);</span><br><span class="line">console.log(success1); // 输出 true 表示库存足够且减少库存成功</span><br><span class="line">const stock2 = getStockByCombination(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;]);</span><br><span class="line">console.log(stock2); // 输出剩余库存 7</span><br><span class="line"></span><br><span class="line">// 尝试减少蓝色、L 尺寸、麻材质的库存数量 5（库存不足）</span><br><span class="line">const success2 = decreaseStock(skus, [&quot;蓝色&quot;, &quot;L&quot;, &quot;麻&quot;], 5);</span><br><span class="line">console.log(success2); // 输出 false 表示库存不足</span><br><span class="line">const stock3 = getStockByCombination(skus, [&quot;蓝色&quot;, &quot;L&quot;, &quot;麻&quot;]);</span><br><span class="line">console.log(stock3); // 输出剩余库存 0</span><br></pre></td></tr></table></figure>

<h2 id="训练代码片段1"><a href="#训练代码片段1" class="headerlink" title="训练代码片段1"></a>训练代码片段1</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=&quot;zh&quot;&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">		&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;</span><br><span class="line">		&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</span><br><span class="line">		&lt;script src=&quot;https://cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.min.js&quot;&gt;&lt;/script&gt;</span><br><span class="line">		&lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">		&lt;style&gt;</span><br><span class="line">			.form .form-item input &#123;</span><br><span class="line">				margin-right: 10px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.form-item+.form-item &#123;</span><br><span class="line">				margin-top: 10px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.form &#123;</span><br><span class="line">				margin-bottom: 10px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			table tr td &#123;</span><br><span class="line">				min-width: 140px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">			.select-box &#123;</span><br><span class="line">				padding-bottom: 100px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .title &#123;</span><br><span class="line">				margin: 10px 0;</span><br><span class="line">				color: black;</span><br><span class="line">				font-weight: bold;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value+.value &#123;</span><br><span class="line">				margin-left: 8px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value &#123;</span><br><span class="line">				padding: 8px 12px;</span><br><span class="line">				background-color: #cccccc;</span><br><span class="line">				color: #333333;</span><br><span class="line">				border-radius: 8px;</span><br><span class="line">				display: inline-block;</span><br><span class="line">				cursor: pointer;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value.active &#123;</span><br><span class="line">				background-color: red;</span><br><span class="line">				color: #FFFFFF;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value.empty &#123;</span><br><span class="line">				background-color: #cccccc;</span><br><span class="line">				color: #f2f2f2;</span><br><span class="line">				pointer-events: none;</span><br><span class="line">			&#125;</span><br><span class="line">		&lt;/style&gt;</span><br><span class="line">	&lt;/head&gt;</span><br><span class="line">	&lt;body&gt;</span><br><span class="line">		&lt;div id=&quot;app&quot;&gt;</span><br><span class="line">			&lt;h4&gt;sku 原始数据&lt;/h4&gt;</span><br><span class="line">			&lt;div class=&quot;wrappar-sku&quot;&gt;</span><br><span class="line">				&lt;div class=&quot;form&quot;&gt;</span><br><span class="line">					&lt;div class=&quot;form-item&quot; v-for=&quot;(item,index) in data&quot; :key=&quot;index&quot;&gt;</span><br><span class="line">						&lt;input type=&quot;text&quot; class=&quot;title&quot; v-model=&quot;item.title&quot;&gt;</span><br><span class="line">						&lt;br /&gt;</span><br><span class="line">						&lt;input type=&quot;text&quot; v-for=&quot;(_item,_index) in item.values&quot;</span><br><span class="line">							@input=&quot;e=&gt; handleInput(e,index,_index)&quot; v-model=&quot;_item&quot; :key=&quot;_index&quot;&gt;</span><br><span class="line">						&lt;button @click=&quot;handleAdd(index)&quot;&gt;添加&lt;/button&gt;</span><br><span class="line">					&lt;/div&gt;</span><br><span class="line">				&lt;/div&gt;</span><br><span class="line">				&lt;button @click=&quot;handleSee&quot;&gt;查看结果&lt;/button&gt;</span><br><span class="line">				&lt;button @click=&quot;handleDataAdd&quot;&gt;新加一条&lt;/button&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">			&lt;hr /&gt;</span><br><span class="line"></span><br><span class="line">			&lt;h4&gt;表格&lt;/h4&gt;</span><br><span class="line">			&lt;table border=&quot;1&quot;&gt;</span><br><span class="line">				&lt;thead&gt;</span><br><span class="line">					&lt;tr&gt;</span><br><span class="line">						&lt;th v-for=&quot;(item,index) in data&quot; :key=&quot;index&quot;&gt; &#123;&#123;item.title&#125;&#125; &lt;/th&gt;</span><br><span class="line">						&lt;th&gt;库存&lt;/th&gt;</span><br><span class="line">					&lt;/tr&gt;</span><br><span class="line">				&lt;/thead&gt;</span><br><span class="line">				&lt;tbody&gt;</span><br><span class="line">					&lt;tr v-for=&quot;(item,index) in skusData&quot; :key=&quot;index&quot;&gt;</span><br><span class="line">						&lt;td v-for=&quot;(_item,_index) in item.combination&quot; v-if=&quot;vIf(item.combination,_index,index)&quot;</span><br><span class="line">							:rowspan=&quot;rowspan(item.combination,_index)&quot; :key=&quot;_index&quot;&gt;</span><br><span class="line">							&#123;&#123;_item&#125;&#125;</span><br><span class="line">						&lt;/td&gt;</span><br><span class="line">						&lt;td&gt; &#123;&#123;item.stock&#125;&#125; &lt;/td&gt;</span><br><span class="line">					&lt;/tr&gt;</span><br><span class="line">				&lt;/tbody&gt;</span><br><span class="line">			&lt;/table&gt;</span><br><span class="line"></span><br><span class="line">			&lt;hr /&gt;</span><br><span class="line"></span><br><span class="line">			&lt;h4&gt;H5 级联选择&lt;/h4&gt;</span><br><span class="line">			&lt;div class=&quot;select-box&quot;&gt;</span><br><span class="line">				&lt;div class=&quot;item&quot; v-for=&quot;(item,index) in data&quot; :key=&quot;index&quot;&gt;</span><br><span class="line">					&lt;div class=&quot;title&quot;&gt;&#123;&#123;item.title&#125;&#125;&lt;/div&gt;</span><br><span class="line">					&lt;div&gt;</span><br><span class="line">						&lt;div v-for=&quot;(_item,_index) in item.values&quot; :key=&quot;_index&quot; class=&quot;value&quot;</span><br><span class="line">							:class=&quot;styleClass(_item,index)&quot; @click=&quot;handleSelect(index,_item)&quot;&gt;</span><br><span class="line">							&#123;&#123;_item&#125;&#125;</span><br><span class="line">						&lt;/div&gt;</span><br><span class="line">					&lt;/div&gt;</span><br><span class="line">				&lt;/div&gt;</span><br><span class="line">				&lt;div&gt;库存量：110&lt;/div&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">		&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">		&lt;script&gt;</span><br><span class="line">			let data = [&#123;</span><br><span class="line">					title: &quot;颜色&quot;,</span><br><span class="line">					values: [&quot;红色&quot;, &quot;蓝色&quot;, &quot;绿色&quot;]</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					title: &quot;尺寸&quot;,</span><br><span class="line">					values: [&quot;S&quot;, &quot;M&quot;, &quot;L&quot;]</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					title: &quot;材质&quot;,</span><br><span class="line">					values: [&quot;棉&quot;, &quot;丝绸&quot;, &quot;麻&quot;]</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					title: &quot;重量&quot;,</span><br><span class="line">					values: [&quot;135kg&quot;, &quot;160kg&quot;, &quot;200kg&quot;, &quot;400kg&quot;]</span><br><span class="line">				&#125;</span><br><span class="line">			];</span><br><span class="line">			let vue = new Vue(&#123;</span><br><span class="line">				el: &quot;#app&quot;,</span><br><span class="line">				data() &#123;</span><br><span class="line">					return &#123;</span><br><span class="line">						data,</span><br><span class="line">						skusData: [],</span><br><span class="line">						selectVal: [],</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;,</span><br><span class="line">				mounted() &#123;</span><br><span class="line">					this.handleSee();</span><br><span class="line">					this.data.forEach(item =&gt; &#123;</span><br><span class="line">						this.selectVal.push(&quot;&quot;);</span><br><span class="line">					&#125;)</span><br><span class="line">				&#125;,</span><br><span class="line">				methods: &#123;</span><br><span class="line">					styleClass(_item, index) &#123;</span><br><span class="line">						let empty = false;</span><br><span class="line">						let selectVal = [...this.selectVal]</span><br><span class="line">						selectVal[index] = _item;</span><br><span class="line">						this.skusData.forEach(item =&gt; &#123;</span><br><span class="line">							let lock = selectVal.some((i, x) =&gt; &#123;</span><br><span class="line">								if (i &amp;&amp; (i != item.combination[x])) &#123;</span><br><span class="line">									return true;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;);</span><br><span class="line">							if (lock) &#123;</span><br><span class="line">								return;</span><br><span class="line">							&#125;;</span><br><span class="line">							selectVal.forEach((i, x) =&gt; &#123;</span><br><span class="line">								if (i &amp;&amp; (i == item.combination[x]) &amp;&amp; (item.stock &lt;= 0)) &#123;</span><br><span class="line">									empty = true;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;);</span><br><span class="line">						&#125;);</span><br><span class="line">						return empty ? &#x27;empty&#x27; : this.selectVal.some(val =&gt; val == _item) ? &#x27;active&#x27; : &#x27;&#x27;;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleSelect(index, val) &#123;</span><br><span class="line">						if (this.selectVal[index] == val) &#123;</span><br><span class="line">							this.selectVal[index] = &quot;&quot;</span><br><span class="line">						&#125; else &#123;</span><br><span class="line">							this.selectVal[index] = val;</span><br><span class="line">						&#125;</span><br><span class="line">						this.skusData.forEach(item =&gt; &#123;</span><br><span class="line">							if (JSON.stringify(item.combination) == JSON.stringify(this.selectVal)) &#123;</span><br><span class="line">								console.log(&#x27;选中的商品：&#x27;, item)</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;);</span><br><span class="line">						this.$forceUpdate();</span><br><span class="line">					&#125;,</span><br><span class="line">					rowspan(val, index) &#123;</span><br><span class="line">						let total = this.skusData.reduce((pev, item) =&gt; &#123;</span><br><span class="line">							let blo = true;</span><br><span class="line">							for (let i = 0; i &lt; (index + 1); i++) &#123;</span><br><span class="line">								if (val[i] != item.combination[i]) &#123;</span><br><span class="line">									blo = false;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							if (blo) &#123;</span><br><span class="line">								pev = pev + 1;</span><br><span class="line">							&#125;;</span><br><span class="line">							return pev;</span><br><span class="line">						&#125;, 0);</span><br><span class="line">						return total;</span><br><span class="line">					&#125;,</span><br><span class="line">					vIf(val, index, skusDataIndex) &#123;</span><br><span class="line">						let show = true;</span><br><span class="line">						this.skusData.forEach((item, n) =&gt; &#123;</span><br><span class="line">							let blo = true;</span><br><span class="line">							for (let i = 0; i &lt; (index + 1); i++) &#123;</span><br><span class="line">								if (val[i] != item.combination[i]) &#123;</span><br><span class="line">									blo = false;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							if (blo &amp;&amp; skusDataIndex &gt; n) &#123;</span><br><span class="line">								show = false;</span><br><span class="line">							&#125;;</span><br><span class="line">						&#125;);</span><br><span class="line">						return show;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleInput(e, index, _index) &#123;</span><br><span class="line">						this.data[index].values[_index] = e.target.value;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleDataAdd() &#123;</span><br><span class="line">						this.data.push(&#123;</span><br><span class="line">							title: &quot;&quot;,</span><br><span class="line">							values: [&quot;&quot;]</span><br><span class="line">						&#125;);</span><br><span class="line">					&#125;,</span><br><span class="line">					handleAdd(index) &#123;</span><br><span class="line">						this.data[index].values.push(&quot;&quot;);</span><br><span class="line">					&#125;,</span><br><span class="line">					handleSee() &#123;</span><br><span class="line">						this.run(this.data);</span><br><span class="line">					&#125;,</span><br><span class="line">					run(options) &#123;</span><br><span class="line">						function generateSKUs(options, initialStock) &#123;</span><br><span class="line">							const skus = [];</span><br><span class="line"></span><br><span class="line">							function backtrack(combination, optionIndex) &#123;</span><br><span class="line">								if (optionIndex === options.length) &#123;</span><br><span class="line">									const sku = &#123;</span><br><span class="line">										combination: combination.slice(),</span><br><span class="line">										stock: initialStock</span><br><span class="line">									&#125;;</span><br><span class="line">									skus.push(sku);</span><br><span class="line">									return;</span><br><span class="line">								&#125;</span><br><span class="line">								const currentOption = options[optionIndex];</span><br><span class="line">								for (let i = 0; i &lt; currentOption.values.length; i++) &#123;</span><br><span class="line">									combination[optionIndex] = currentOption.values[i];</span><br><span class="line">									backtrack(combination, optionIndex + 1);</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							backtrack([], 0);</span><br><span class="line">							return skus;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						const skus = generateSKUs(options, 10);</span><br><span class="line"></span><br><span class="line">						function getStockByCombination(skus, combination) &#123; //获取库存</span><br><span class="line">							for (const sku of skus) &#123;</span><br><span class="line">								if (JSON.stringify(sku.combination) === JSON.stringify(combination)) &#123;</span><br><span class="line">									return sku.stock;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							return 0;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						function decreaseStock(skus, combination, quantity) &#123; // 减少库存</span><br><span class="line">							for (const sku of skus) &#123;</span><br><span class="line">								if (JSON.stringify(sku.combination) === JSON.stringify(combination)) &#123;</span><br><span class="line">									sku.stock -= quantity;</span><br><span class="line">									return sku.stock &gt;= 0;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							return false;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						console.log(&#x27;原始数据&#x27;, options)</span><br><span class="line">						console.log(&#x27;sku化数据:&#x27;, skus);</span><br><span class="line">						this.skusData = skus;</span><br><span class="line"></span><br><span class="line">						// 	const stock1 = getStockByCombination(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;]);</span><br><span class="line">						// 	console.log(stock1); // 输出初始库存 10</span><br><span class="line"></span><br><span class="line">						// 	// 减少红色、M 尺寸、棉材质的库存数量 3</span><br><span class="line">						const success1 = decreaseStock(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;, &quot;400kg&quot;], 10);</span><br><span class="line">						// 	console.log(success1); // 输出 true 表示库存足够且减少库存成功</span><br><span class="line">						// 	const stock2 = getStockByCombination(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;]);</span><br><span class="line">						// 	console.log(stock2); // 输出剩余库存 7</span><br><span class="line"></span><br><span class="line">						// 	// 尝试减少蓝色、L 尺寸、麻材质的库存数量 5（库存不足）</span><br><span class="line">						// 	const success2 = decreaseStock(skus, [&quot;蓝色&quot;, &quot;L&quot;, &quot;麻&quot;], 5);</span><br><span class="line">						// 	console.log(success2); // 输出 false 表示库存不足</span><br><span class="line">						// 	const stock3 = getStockByCombination(skus, [&quot;蓝色&quot;, &quot;L&quot;, &quot;麻&quot;]);</span><br><span class="line">						// 	console.log(stock3); // 输出剩余库存 0</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;,</span><br><span class="line">			&#125;)</span><br><span class="line">		&lt;/script&gt;</span><br><span class="line">	&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="训练代码片段2"><a href="#训练代码片段2" class="headerlink" title="训练代码片段2"></a>训练代码片段2</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=&quot;zh&quot;&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">		&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;</span><br><span class="line">		&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</span><br><span class="line">		&lt;script src=&quot;https://cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.min.js&quot;&gt;&lt;/script&gt;</span><br><span class="line">		&lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">		&lt;style&gt;</span><br><span class="line">			.form .form-item input &#123;</span><br><span class="line">				margin-right: 10px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.form-item+.form-item &#123;</span><br><span class="line">				margin-top: 10px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.form &#123;</span><br><span class="line">				margin-bottom: 10px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			table tr td &#123;</span><br><span class="line">				min-width: 140px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">			.select-box &#123;</span><br><span class="line">				padding-bottom: 100px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .title &#123;</span><br><span class="line">				margin: 10px 0;</span><br><span class="line">				color: black;</span><br><span class="line">				font-weight: bold;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value+.value &#123;</span><br><span class="line">				margin-left: 8px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value &#123;</span><br><span class="line">				padding: 8px 12px;</span><br><span class="line">				background-color: #cccccc;</span><br><span class="line">				color: #333333;</span><br><span class="line">				border-radius: 8px;</span><br><span class="line">				display: inline-block;</span><br><span class="line">				cursor: pointer;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value.active &#123;</span><br><span class="line">				background-color: red;</span><br><span class="line">				color: #FFFFFF;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.select-box .item .value.empty &#123;</span><br><span class="line">				background-color: #cccccc;</span><br><span class="line">				color: #f2f2f2;</span><br><span class="line">				pointer-events: none;</span><br><span class="line">			&#125;</span><br><span class="line">		&lt;/style&gt;</span><br><span class="line">	&lt;/head&gt;</span><br><span class="line">	&lt;body&gt;</span><br><span class="line">		&lt;div id=&quot;app&quot;&gt;</span><br><span class="line">			&lt;h4&gt;sku 原始数据&lt;/h4&gt;</span><br><span class="line">			&lt;div class=&quot;wrappar-sku&quot;&gt;</span><br><span class="line">				&lt;div class=&quot;form&quot;&gt;</span><br><span class="line">					&lt;div class=&quot;form-item&quot; v-for=&quot;(item,index) in data&quot; :key=&quot;index&quot;&gt;</span><br><span class="line">						&lt;input type=&quot;text&quot; class=&quot;title&quot; v-model=&quot;item.title&quot;&gt;</span><br><span class="line">						&lt;br /&gt;</span><br><span class="line">						&lt;input type=&quot;text&quot; v-for=&quot;(_item,_index) in item.values&quot;</span><br><span class="line">							@input=&quot;e=&gt; handleInput(e,index,_index)&quot; v-model=&quot;_item&quot; :key=&quot;_index&quot;&gt;</span><br><span class="line">						&lt;button @click=&quot;handleAdd(index)&quot;&gt;添加&lt;/button&gt;</span><br><span class="line">					&lt;/div&gt;</span><br><span class="line">				&lt;/div&gt;</span><br><span class="line">				&lt;button @click=&quot;handleSee&quot;&gt;查看结果&lt;/button&gt;</span><br><span class="line">				&lt;button @click=&quot;handleDataAdd&quot;&gt;新加一条&lt;/button&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">			&lt;hr /&gt;</span><br><span class="line"></span><br><span class="line">			&lt;h4&gt;表格&lt;/h4&gt;</span><br><span class="line">			&lt;table border=&quot;1&quot;&gt;</span><br><span class="line">				&lt;thead&gt;</span><br><span class="line">					&lt;tr&gt;</span><br><span class="line">						&lt;th v-for=&quot;(item,index) in data&quot; :key=&quot;index&quot;&gt; &#123;&#123;item.title&#125;&#125; &lt;/th&gt;</span><br><span class="line">						&lt;th&gt;库存&lt;/th&gt;</span><br><span class="line">					&lt;/tr&gt;</span><br><span class="line">				&lt;/thead&gt;</span><br><span class="line">				&lt;tbody&gt;</span><br><span class="line">					&lt;tr v-for=&quot;(item,index) in skusData&quot; :key=&quot;index&quot;&gt;</span><br><span class="line">						&lt;td v-for=&quot;(_item,_index) in item.combination&quot; v-if=&quot;vIf(item.combination,_index,index)&quot;</span><br><span class="line">							:rowspan=&quot;rowspan(item.combination,_index)&quot; :key=&quot;_index&quot;&gt;</span><br><span class="line">							&#123;&#123;_item&#125;&#125;</span><br><span class="line">						&lt;/td&gt;</span><br><span class="line">						&lt;td&gt; &#123;&#123;item.stock&#125;&#125; &lt;/td&gt;</span><br><span class="line">					&lt;/tr&gt;</span><br><span class="line">				&lt;/tbody&gt;</span><br><span class="line">			&lt;/table&gt;</span><br><span class="line"></span><br><span class="line">			&lt;hr /&gt;</span><br><span class="line"></span><br><span class="line">			&lt;h4&gt;H5 选择器&lt;/h4&gt;</span><br><span class="line">			&lt;div class=&quot;select-box&quot;&gt;</span><br><span class="line">				&lt;div class=&quot;item&quot; v-for=&quot;(item,index) in selectData&quot; :key=&quot;index&quot;&gt;</span><br><span class="line">					&lt;div class=&quot;title&quot;&gt;&#123;&#123;item.title&#125;&#125;&lt;/div&gt;</span><br><span class="line">					&lt;div&gt;</span><br><span class="line">						&lt;div v-for=&quot;(_item,_index) in item.values&quot; :key=&quot;_index&quot; class=&quot;value&quot;</span><br><span class="line">							:class=&quot;_item.className&quot; @click=&quot;handleSelect(index,_item.value)&quot;&gt;</span><br><span class="line">							&#123;&#123;_item.value&#125;&#125;</span><br><span class="line">						&lt;/div&gt;</span><br><span class="line">					&lt;/div&gt;</span><br><span class="line">				&lt;/div&gt;</span><br><span class="line">			&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">		&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">		&lt;script&gt;</span><br><span class="line">			let data = [&#123;</span><br><span class="line">					title: &quot;颜色&quot;,</span><br><span class="line">					values: [&quot;红色&quot;, &quot;蓝色&quot;, &quot;绿色&quot;]</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					title: &quot;尺寸&quot;,</span><br><span class="line">					values: [&quot;S&quot;, &quot;M&quot;, &quot;L&quot;]</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					title: &quot;材质&quot;,</span><br><span class="line">					values: [&quot;棉&quot;, &quot;丝绸&quot;, &quot;麻&quot;]</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					title: &quot;重量&quot;,</span><br><span class="line">					values: [&quot;135kg&quot;, &quot;160kg&quot;, &quot;200kg&quot;, &quot;400kg&quot;]</span><br><span class="line">				&#125;</span><br><span class="line">			];</span><br><span class="line">			let vue = new Vue(&#123;</span><br><span class="line">				el: &quot;#app&quot;,</span><br><span class="line">				data() &#123;</span><br><span class="line">					return &#123;</span><br><span class="line">						data,</span><br><span class="line">						selectData:[],</span><br><span class="line">						skusData: [],</span><br><span class="line">						selectVal: [],</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;,</span><br><span class="line">				mounted() &#123;</span><br><span class="line">					this.handleSee();</span><br><span class="line">					this.data.forEach(item =&gt; &#123;</span><br><span class="line">						this.selectVal.push(&quot;&quot;);</span><br><span class="line">					&#125;)</span><br><span class="line">				&#125;,</span><br><span class="line">				methods: &#123;</span><br><span class="line">					styleClass(_item, index) &#123;</span><br><span class="line">						let empty = false;</span><br><span class="line">						let selectVal = [...this.selectVal]</span><br><span class="line">						selectVal[index] = _item;</span><br><span class="line">						this.skusData.forEach(item =&gt; &#123;</span><br><span class="line">							let lock = selectVal.some((i, x) =&gt; &#123;</span><br><span class="line">								if (i &amp;&amp; (i != item.combination[x])) &#123;</span><br><span class="line">									return true;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;);</span><br><span class="line">							if (lock) &#123;</span><br><span class="line">								return;</span><br><span class="line">							&#125;;</span><br><span class="line">							selectVal.forEach((i, x) =&gt; &#123;</span><br><span class="line">								if (i &amp;&amp; (i == item.combination[x]) &amp;&amp; (item.stock &lt;= 0)) &#123;</span><br><span class="line">									empty = true;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;);</span><br><span class="line">						&#125;);</span><br><span class="line">						return empty ? &#x27;empty&#x27; : this.selectVal.some(val =&gt; val == _item) ? &#x27;active&#x27; : &#x27;&#x27;;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleSelect(index, val) &#123;</span><br><span class="line">						if (this.selectVal[index] == val) &#123;</span><br><span class="line">							this.selectVal[index] = &quot;&quot;</span><br><span class="line">						&#125; else &#123;</span><br><span class="line">							this.selectVal[index] = val;</span><br><span class="line">						&#125;</span><br><span class="line">						this.skusData.forEach(item =&gt; &#123;</span><br><span class="line">							if (JSON.stringify(item.combination) == JSON.stringify(this.selectVal)) &#123;</span><br><span class="line">								console.log(&#x27;选中的商品：&#x27;, item)</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;);</span><br><span class="line">						this.handleSelectData();</span><br><span class="line">					&#125;,</span><br><span class="line">					rowspan(val, index) &#123;</span><br><span class="line">						let total = this.skusData.reduce((pev, item) =&gt; &#123;</span><br><span class="line">							let blo = true;</span><br><span class="line">							for (let i = 0; i &lt; (index + 1); i++) &#123;</span><br><span class="line">								if (val[i] != item.combination[i]) &#123;</span><br><span class="line">									blo = false;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							if (blo) &#123;</span><br><span class="line">								pev = pev + 1;</span><br><span class="line">							&#125;;</span><br><span class="line">							return pev;</span><br><span class="line">						&#125;, 0);</span><br><span class="line">						return total;</span><br><span class="line">					&#125;,</span><br><span class="line">					vIf(val, index, skusDataIndex) &#123;</span><br><span class="line">						let show = true;</span><br><span class="line">						this.skusData.forEach((item, n) =&gt; &#123;</span><br><span class="line">							let blo = true;</span><br><span class="line">							for (let i = 0; i &lt; (index + 1); i++) &#123;</span><br><span class="line">								if (val[i] != item.combination[i]) &#123;</span><br><span class="line">									blo = false;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							if (blo &amp;&amp; skusDataIndex &gt; n) &#123;</span><br><span class="line">								show = false;</span><br><span class="line">							&#125;;</span><br><span class="line">						&#125;);</span><br><span class="line">						return show;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleInput(e, index, _index) &#123;</span><br><span class="line">						this.data[index].values[_index] = e.target.value;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleDataAdd() &#123;</span><br><span class="line">						this.data.push(&#123;</span><br><span class="line">							title: &quot;&quot;,</span><br><span class="line">							values: [&quot;&quot;]</span><br><span class="line">						&#125;);</span><br><span class="line">					&#125;,</span><br><span class="line">					handleAdd(index) &#123;</span><br><span class="line">						this.data[index].values.push(&quot;&quot;);</span><br><span class="line">					&#125;,</span><br><span class="line">					handleSelectData()&#123;</span><br><span class="line">						let selectData = data.map(item=&gt;&#123;</span><br><span class="line">							return &#123;</span><br><span class="line">								...item,</span><br><span class="line">								values: item.values.map(value=&gt;&#123;</span><br><span class="line">									return &#123;</span><br><span class="line">										value,</span><br><span class="line">										className: null</span><br><span class="line">									&#125;</span><br><span class="line">								&#125;)</span><br><span class="line">							&#125;</span><br><span class="line">						&#125;);</span><br><span class="line">						selectData.forEach((_item,index)=&gt;&#123;</span><br><span class="line">							_item.values.forEach(obj=&gt;&#123;</span><br><span class="line">								let empty = false;</span><br><span class="line">								let selectVal = [...this.selectVal];</span><br><span class="line">								selectVal[index] = obj.value;</span><br><span class="line">								this.skusData.forEach(item =&gt; &#123;</span><br><span class="line">									let lock = selectVal.some((i, x) =&gt; &#123;</span><br><span class="line">										if (i &amp;&amp; (i != item.combination[x])) &#123;</span><br><span class="line">											return true;</span><br><span class="line">										&#125;</span><br><span class="line">									&#125;);</span><br><span class="line">									if (lock) &#123;</span><br><span class="line">										return;</span><br><span class="line">									&#125;;</span><br><span class="line">									selectVal.forEach((i, x) =&gt; &#123;</span><br><span class="line">										if (i &amp;&amp; (i == item.combination[x]) &amp;&amp; (item.stock &lt;= 0)) &#123;</span><br><span class="line">											empty = true;</span><br><span class="line">										&#125;</span><br><span class="line">									&#125;);</span><br><span class="line">								&#125;);</span><br><span class="line">								obj.className = empty ? &#x27;empty&#x27; : this.selectVal.some(val =&gt; val == obj.value) ? &#x27;active&#x27; : &#x27;&#x27;;</span><br><span class="line">							&#125;)</span><br><span class="line">						&#125;);</span><br><span class="line">						this.selectData = selectData;</span><br><span class="line">					&#125;,</span><br><span class="line">					handleSee() &#123;</span><br><span class="line">						this.run(this.data);</span><br><span class="line">						this.handleSelectData();</span><br><span class="line">					&#125;,</span><br><span class="line">					run(options) &#123;</span><br><span class="line">						function generateSKUs(options, initialStock) &#123;</span><br><span class="line">							const skus = [];</span><br><span class="line"></span><br><span class="line">							function backtrack(combination, optionIndex) &#123;</span><br><span class="line">								if (optionIndex === options.length) &#123;</span><br><span class="line">									const sku = &#123;</span><br><span class="line">										combination: combination.slice(),</span><br><span class="line">										stock: initialStock</span><br><span class="line">									&#125;;</span><br><span class="line">									skus.push(sku);</span><br><span class="line">									return;</span><br><span class="line">								&#125;</span><br><span class="line">								const currentOption = options[optionIndex];</span><br><span class="line">								for (let i = 0; i &lt; currentOption.values.length; i++) &#123;</span><br><span class="line">									combination[optionIndex] = currentOption.values[i];</span><br><span class="line">									backtrack(combination, optionIndex + 1);</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							backtrack([], 0);</span><br><span class="line">							return skus;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						const skus = generateSKUs(options, 10);</span><br><span class="line"></span><br><span class="line">						function getStockByCombination(skus, combination) &#123; //获取库存</span><br><span class="line">							for (const sku of skus) &#123;</span><br><span class="line">								if (JSON.stringify(sku.combination) === JSON.stringify(combination)) &#123;</span><br><span class="line">									return sku.stock;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							return 0;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						function decreaseStock(skus, combination, quantity) &#123; // 减少库存</span><br><span class="line">							for (const sku of skus) &#123;</span><br><span class="line">								if (JSON.stringify(sku.combination) === JSON.stringify(combination)) &#123;</span><br><span class="line">									sku.stock -= quantity;</span><br><span class="line">									return sku.stock &gt;= 0;</span><br><span class="line">								&#125;</span><br><span class="line">							&#125;</span><br><span class="line">							return false;</span><br><span class="line">						&#125;</span><br><span class="line"></span><br><span class="line">						console.log(&#x27;原始数据&#x27;, options)</span><br><span class="line">						console.log(&#x27;sku化数据:&#x27;, skus);</span><br><span class="line">						this.skusData = skus;</span><br><span class="line"></span><br><span class="line">						// 	const stock1 = getStockByCombination(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;]);</span><br><span class="line">						// 	console.log(stock1); // 输出初始库存 10</span><br><span class="line"></span><br><span class="line">						// 	// 减少红色、M 尺寸、棉材质的库存数量 3</span><br><span class="line">						const success1 = decreaseStock(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;, &quot;400kg&quot;], 10);</span><br><span class="line">						// 	console.log(success1); // 输出 true 表示库存足够且减少库存成功</span><br><span class="line">						// 	const stock2 = getStockByCombination(skus, [&quot;红色&quot;, &quot;M&quot;, &quot;棉&quot;]);</span><br><span class="line">						// 	console.log(stock2); // 输出剩余库存 7</span><br><span class="line"></span><br><span class="line">						// 	// 尝试减少蓝色、L 尺寸、麻材质的库存数量 5（库存不足）</span><br><span class="line">						// 	const success2 = decreaseStock(skus, [&quot;蓝色&quot;, &quot;L&quot;, &quot;麻&quot;], 5);</span><br><span class="line">						// 	console.log(success2); // 输出 false 表示库存不足</span><br><span class="line">						// 	const stock3 = getStockByCombination(skus, [&quot;蓝色&quot;, &quot;L&quot;, &quot;麻&quot;]);</span><br><span class="line">						// 	console.log(stock3); // 输出剩余库存 0</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;,</span><br><span class="line">			&#125;)</span><br><span class="line">		&lt;/script&gt;</span><br><span class="line">		&lt;script&gt;</span><br><span class="line">			let str = &quot;213214214213213&quot;;</span><br><span class="line">			// alert(str.substring(str.length-3,str.length))</span><br><span class="line">			function look() &#123;</span><br><span class="line">				alert(this)</span><br><span class="line">			&#125;</span><br><span class="line">			// look.apply(213)</span><br><span class="line">		&lt;/script&gt;</span><br><span class="line">	&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure></div>
        </div>
        
            <div class="kratos-copyright text-center clearfix">
                <h5 itemprop="copyrightNotice">本作品采用 <a rel="license nofollow" target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/">知识共享署名-相同方式共享 4.0 国际许可协议</a> 进行许可</h5>
            </div>
        
        <footer class="kratos-entry-footer clearfix">
            
                <div class="post-like-donate text-center clearfix" id="post-like-donate">
                
                
                    <a class="share" href="javascript:;"><i class="fa fa-share-alt"></i> 分享</a>
                    <div class="share-wrap" style="display: none;">
    <div class="share-group">
        <a href="javascript:;" class="share-plain qq" onclick="share('qq');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-qq"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain qzone" onclick="share('qzone');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-star"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain weixin pop style-plain" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-weixin"></i>
            </div>
            <div class="share-int">
                <div class="qrcode" id="wechat-qr"></div>
                <p>打开微信“扫一扫”，打开网页后点击屏幕右上角分享按钮</p>
            </div>
        </a>
        <a href="javascript:;" class="share-plain weibo" onclick="share('weibo');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-weibo"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain facebook style-plain" onclick="share('facebook');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-facebook"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain twitter style-plain" onclick="share('twitter');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-twitter"></i>
            </div>
        </a>
    </div>
    <script type="text/javascript">
        $(()=>{
            new QRCode("wechat-qr", {
                text: "https://slsandxr.top/2023/08/31/JS/Js-sku%E5%95%86%E5%93%81%E8%A7%84%E5%88%99/",
                width: 150,
                height: 150,
                correctLevel : QRCode.CorrectLevel.H
            });
        });
        function share(dest) {
            const qqBase        = "https://connect.qq.com/widget/shareqq/index.html?";
            const weiboBase     = "https://service.weibo.com/share/share.php?";
            const qzoneBase     = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?";
            const facebookBase  = "https://www.facebook.com/sharer/sharer.php?";
            const twitterBase   = "https://twitter.com/intent/tweet?";
            const hostUrl       = "https://slsandxr.top/2023/08/31/JS/Js-sku%E5%95%86%E5%93%81%E8%A7%84%E5%88%99/";
            const title         = "「Js-sku商品规则」";
            const excerpt       = `Js代码片段123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960...`;
            let _URL;
            switch (dest) {
                case "qq"       : _URL = qqBase+"url="+hostUrl+"&title="+title+"&desc=&summary="+excerpt+"&site=cxpy";     break;
                case "weibo"    : _URL = weiboBase+"url="+hostUrl+"&title="+title+excerpt;                                 break;
                case "qzone"    : _URL = qzoneBase+"url="+hostUrl+"&title="+title+"&desc=&summary="+excerpt+"&site=cxpy";  break;
                case "facebook" : _URL = facebookBase+"u="+hostUrl;                                                        break;
                case "twitter"  : _URL = twitterBase+"text="+title+excerpt+"&url="+hostUrl;                                break;
            }
            window.open(_URL);
        };
    </script>
</div>
                
                </div>
            
            <div class="footer-tag clearfix">
                <div class="pull-left">
                <i class="fa fa-tags"></i>
                    <a class="tag-none-link" href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag">前端</a>
                </div>
                <div class="pull-date">
                    <time datetime="2024-12-16T11:07:04.232Z" itemprop="dateModified">最后编辑：2024-12-16</time>
                </div>
            </div>
        </footer>
    </div>
    
        <nav class="navigation post-navigation clearfix" role="navigation">
            
            <div class="nav-previous clearfix">
                <a title=" 排忧解难" href="/2023/07/28/排忧解难/">&lt; 上一篇</a>
            </div>
            
            
            <div class="nav-next clearfix">
                <a title=" canvas实现盖章" href="/2023/10/07/JS/canvas实现盖章/">下一篇 &gt;</a>
            </div>
            
        </nav>
    
    
</article>

        

            </section>

        

                
            

<section id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm">
    <!-- 文章和页面根据splitter来分割，没有的话就从头开始设置为sticky -->
    
    
                <aside id="krw-about" class="widget widget-kratos-about clearfix">
    <div class="photo-background"></div>
    <div class="photo-wrapper clearfix">
        <div class="photo-wrapper-tip text-center">
            <img class="about-photo" src="/images/avatar.webp" loading="lazy" decoding="auto" />
        </div>
    </div>
    <div class="textwidget">
        <p class="text-center">孙刘森的博客</p>
    </div>
    <div class="site-meta">
        <a class="meta-item" href="/archives/">
            <span class="title">
                文章
            </span>
            <span class="count">
                34
            </span>
        </a>
        <a class="meta-item" href="/categories/">
            <span class="title">
                分类
            </span>
            <span class="count">
                11
            </span>
        </a>
        <a class="meta-item" href="/tags/">
            <span class="title">
                标签
            </span>
            <span class="count">
                18
            </span>
        </a>
    </div>
</aside>
            
                    <div class="sticky-area">
                
                
  <aside id="krw-categories" class="widget widget-kratos-categories clearfix">
    <h4 class="widget-title"><i class="fa fa-folder"></i>分类目录</h4>
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Js/">Js</a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/PETS-3/">PETS-3</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Tools/">Tools</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/UniCloud/">UniCloud</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AD%99%E5%88%98%E6%A3%AE%E7%9A%84%E8%B4%A6%E6%9C%AC/">孙刘森的账本</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%89%E5%8D%93/">安卓</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/">我的博客</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8E%92%E5%BF%A7%E8%A7%A3%E9%9A%BE/">排忧解难</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/">服务器</a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%A7%8D%E5%AD%90/">种子</a><span class="category-list-count">1</span></li></ul>
  </aside>


            
                
  <aside id="krw-tags" class="widget widget-kratos-tags clearfix">
    <h4 class="widget-title"><i class="fa fa-tags"></i>标签聚合</h4>
      <div class="tag-clouds">
        <a href="/tags/Docker/" style="font-size: 0.6em;">Docker</a> <a href="/tags/Java/" style="font-size: 0.6em;">Java</a> <a href="/tags/Linux/" style="font-size: 0.73em;">Linux</a> <a href="/tags/Mindway-js/" style="font-size: 0.6em;">Mindway.js</a> <a href="/tags/Mysql/" style="font-size: 0.6em;">Mysql</a> <a href="/tags/Nginx/" style="font-size: 0.67em;">Nginx</a> <a href="/tags/Node/" style="font-size: 0.6em;">Node</a> <a href="/tags/PETS-3/" style="font-size: 0.6em;">PETS-3</a> <a href="/tags/UniCloud/" style="font-size: 0.6em;">UniCloud</a> <a href="/tags/Vue3/" style="font-size: 0.6em;">Vue3</a> <a href="/tags/apk/" style="font-size: 0.6em;">apk</a> <a href="/tags/%E5%89%8D%E7%AB%AF/" style="font-size: 0.8em;">前端</a> <a href="/tags/%E5%89%8D%E7%AB%AF%E5%AD%98%E5%82%A8/" style="font-size: 0.6em;">前端存储</a> <a href="/tags/%E5%AD%99%E5%88%98%E6%A3%AE%E7%9A%84%E8%B4%A6%E6%9C%AC/" style="font-size: 0.6em;">孙刘森的账本</a> <a href="/tags/%E5%B7%A5%E5%85%B7/" style="font-size: 0.67em;">工具</a> <a href="/tags/%E6%8E%92%E5%BF%A7%E8%A7%A3%E9%9A%BE/" style="font-size: 0.6em;">排忧解难</a> <a href="/tags/%E7%A7%8D%E5%AD%90/" style="font-size: 0.6em;">种子</a> <a href="/tags/%E9%80%82%E9%85%8D/" style="font-size: 0.6em;">适配</a>
      </div>
  </aside>

            
                
  <aside id="krw-posts" class="widget widget-kratos-posts">
  <h4 class="widget-title"><i class="fa fa-file"></i>最新文章</h4>
  <div class="tab-content">
      <ul class="list-group">
        
        
          
          
            <a class="list-group-item" href="/2024/06/06/JS/%E9%80%82%E9%85%8D%E4%BB%A3%E7%A0%81/"><i class="fa  fa-book"></i> 前端rem适配代码</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/10/07/JS/canvas%E5%AE%9E%E7%8E%B0%E7%9B%96%E7%AB%A0/"><i class="fa  fa-book"></i> canvas实现盖章</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/08/31/JS/Js-sku%E5%95%86%E5%93%81%E8%A7%84%E5%88%99/"><i class="fa  fa-book"></i> Js-sku商品规则</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/07/28/%E6%8E%92%E5%BF%A7%E8%A7%A3%E9%9A%BE/"><i class="fa  fa-book"></i> 排忧解难</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/07/25/JS/Js%E5%AE%9E%E7%8E%B0%E8%A7%A3%E6%9E%90gif%E5%8A%A8%E5%9B%BE%E5%92%8C%E5%90%88%E6%88%90gif%E5%8A%A8%E5%9B%BE/"><i class="fa  fa-book"></i> Js实现解析gif动图和合成gif动图</a>
            
          
        
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
      </ul>
  </div>
  </aside>

            
    </div>
</section>
        
        </div>
    </div>
</div>
<footer>
    <div id="footer"  class="ap-lrc"  >
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <ul class="kratos-social-icons">
                        <!-- Keep for compatibility -->
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        <!-- New links -->
                        
                    </ul>
                    <ul class="kratos-copyright">
                        <div>
                            <li>&copy; 2024 Blog 版权所有.</li>
                            <li>本站已运行<span id="span_dt">Loading...</span></li>
                        </div>
                        <div>
                            <li>Theme <a href="https://github.com/Candinya/Kratos-Rebirth" target="_blank">Kratos:Rebirth</a></li>
                            <li>Site built with&nbsp;<i class="fa fa-heart throb" style="color:#d43f57"></i>&nbsp;by Sun Liusen.</li>
                        </div>
                        <div>
                            <li>Powered by <a href="https://hexo.io" target="_blank" rel="nofollow">Hexo</a></li>
                            <li>Hosted on <a href="https://github.io" target="_blank">Github Pages</a></li>
                        </div>
                        <div>
                            
                            
                        </div>
                    </ul>
                </div>
            </div>
        </div>
        <div class="kr-tool text-center">
            <div class="tool">
                
                    <div class="box search-box">
                        <a href="/search/">
                            <span class="fa fa-search"></span>
                        </a>
                    </div>
                
                
                    <div class="box theme-box" id="darkmode-switch">
                        <span class="fa fa-adjust"></span>
                    </div>
                
                
                
            </div>
            <div class="box gotop-box">
                <span class="fa fa-chevron-up"></span>
            </div>
        </div>
    </div>
</footer>
</div>
</div>

        <script defer src="/vendors/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
<script defer src="/vendors/nprogress@0.2.0/nprogress.js"></script>
<script>
    if (!window.kr) {
        window.kr = {};
    }
    window.kr.notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));
    window.kr.siteRoot = "/";
</script>


    <script async src="/js/candy.min.js"></script>



    <script defer src="/vendors/aplayer@1.10.1/dist/APlayer.min.js"></script>
    
    <script defer src="/vendors/meting@2.0.1/dist/Meting.min.js"></script>
    <meting-js
        server="netease"
        type="playlist"
        id="3204190542"
        order="random"
        fixed="true"
    >
    </meting-js>



    <script defer src="/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

<script defer src="/js/kratosr.min.js"></script>
<script defer src="/js/pjax.min.js"></script>



<!-- Extra support for third-party plguins  -->


    </body>
</html>